using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.ComponentModel;

namespace BPMVE_XPDL_Library
{
    /// <summary>
    /// 7.6.5.3.7. TaskService 
    /// A Service Task is a Task that provides some sort of Service, which could be a Web Service 
    /// OR an automated application.
    /// </summary>
    public class TaskService : IValidate
    {
        /// <summary>
        /// A Message for the InMessage attribute may be entered. This indicates that the Message 
        /// will be received at the Start of the Task, After the availability of any defined 
        /// InputSets (child element of Activity). One OR more corresponding incoming Message Flows 
        /// MAY be shown on the diagram. However, the display of the Message Flow is not required.
        /// The Message is applied To All incoming Message Flow, but can arrive for only One of the 
        /// incoming Message Flow for a single instance of the Task.See Section 7.9.4.
        /// </summary>
        [XmlElement("MessageIn")]
        public Message MessageIn { get; set; }
		[XmlIgnore]
		public bool MessageInSpecified { get { return MessageIn  != null; } }

        /// <summary>
        /// A Message for the OutMessage attribute may be entered. The sending of this Message 
        /// marks the completion of the Task, which may cause the production of an OutputSet 
        /// (child element of Activity One OR more corresponding outgoing Message Flow MAY be 
        /// shown on the diagram. However, the display of the Message Flow is not required. The
        /// Message is applied To All outgoing Message Flow AND the Message will be sent down 
        /// All outgoing Message Flow at the completion of a single instance of the Task. 
        /// See section 7.9.4.
        /// </summary>
        [XmlElement("MessageOut")]
        public Message MessageOut { get; set; }
		[XmlIgnore]
		public bool MessageOutSpecified { get { return MessageOut  != null; } }

        /// <summary>
        /// Describes the web services operation To be used by this task. See section 7.9.6.
        /// </summary>
        [XmlElement("WebServiceOperation")]
        public WebServiceOperation WebServiceOperation { get; set; }
        [XmlIgnore]
        public bool WebServiceOperationSpecified { get { return WebServiceOperation != null; } }

        /// <summary>
        /// Describes how To process faults generated by the web Service operation in this task. 
        /// See section 7.9.7.
        /// </summary>
        [XmlArray("WebServiceFaultCatch")]
        public List<WebServiceFaultCatch> WebserviceFaultCatch { get; set; }
		[XmlIgnore]
		public bool WebserviceFaultCatchSpecified { get { return WebserviceFaultCatch == null ? false : WebserviceFaultCatch.Count != 0; } }

        /// <summary>
        /// WebService | Other | Unspecified
        /// </summary>
        [XmlAttribute("Implementation")]
        [DefaultValue(ImplementationEnum.WebService)]
        public ImplementationEnum Implementation { get; set; }
        //[XmlIgnore]
        //public bool ImplementationSpecified { get { return Implementation != null; } }



        public TaskService()
        {
            Implementation = ImplementationEnum.WebService;
        }
		
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
        {
            TaskService value = obj as TaskService;
            if (value != null)
            {
                List<object> listA = new List<object>
                {
                    this.Implementation, this.MessageIn, this.MessageOut, this.WebServiceOperation
                };

                List<object> listB = new List<object>
                {
                    value.Implementation, value.MessageIn, value.MessageOut, value.WebServiceOperation
                };

                if (!Utilities.IsListEqual<WebServiceFaultCatch>(this.WebserviceFaultCatch, value.WebserviceFaultCatch))
                    return false;

                return (Utilities.IsEqual(listA, listB));
            }

            return false;
        }

        #region IValidate Members

        public bool Validate()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}